<template>
  <div class="wrapper">
    <swiper ref="mySwiper" :options="swiperOptions" v-if="showSwiper">
      <swiper-slide v-for="item of list" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl">
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
  export default {
    name: 'HomeSwiper',
    props: {
      list: Array
    },
    data () {
      return {
        swiperOptions: {
          pagination: '.swiper-pagination',
          loop: false,
          slidesPerView :'auto',
          // paginationType: 'fraction',
          // paginationType : 'progress',
          // paginationType : 'custom',
        }
      }
    },
    // 计算属性
    computed: {
      // 解决轮播图，跳到最后一张图显示
      showSwiper () {
        return this.list.length
      }
    }

  }
</script>

<style scoped lang="stylus">
  @import "~styles/varibles.styl"
  .wrapper >>> .swiper-pagination-current, .wrapper >>> .swiper-pagination-total
    color black

  .wrapper >>> .swiper-pagination-bullet-active
    background white


  .wrapper
    overflow hidden
    width 100%
    height 0
    padding-bottom 40%
    background #eaeaea

  .swiper-img
    width 100%

  .swiper-pagination
    bottom 0.5rem
</style>
